﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien;
using QuanLyThuVien.VO;
using QuanLyThuVien.BUS;

namespace QuanLyThuVien
{
    public partial class frmThemMuonTra : Form
    {
        public frmThemMuonTra()
        {
            InitializeComponent();
        }

        private void frmThemMuonTra_Load(object sender, EventArgs e)
        {
            busDocGia busDocGia = new busDocGia();
            DocGia DocGia = new DocGia(txtMaDocGia.Text, txtTenDocGia.Text);
            dtgvThongTinDocGia.DataSource = busDocGia.TimDocGia(DocGia);

            busSach busSach = new busSach();
            Sach Sach = new Sach(txtMaSach.Text, txtTenSach.Text, txtTacGia.Text, txtNhaXuatBan.Text);
            dtgvThongTinSach.DataSource = busSach.TimSach(Sach);

        }

        private void btnTimKiemSach_Click(object sender, EventArgs e)
        {
            busSach busSach = new busSach();
            Sach Sach = new Sach(txtMaSach.Text, txtTenSach.Text, txtTacGia.Text, txtNhaXuatBan.Text);
            dtgvThongTinSach.DataSource = busSach.TimSach(Sach);
        }

        private void btnTimKiemDocGia_Click(object sender, EventArgs e)
        {
            busDocGia busDocGia = new busDocGia();
            DocGia DocGia = new DocGia(txtMaDocGia.Text, txtTenDocGia.Text);
            dtgvThongTinDocGia.DataSource = busDocGia.TimDocGia(DocGia);
        }

        private void dtgvThongTinSach_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (dtgvThongTinSach.Rows == null)
            {
                txtThemMaSach.Text = "";
                return;
            }
            txtThemMaSach.Text = dtgvThongTinSach.Rows[e.RowIndex].Cells[0].Value.ToString();
        }

        private void dtgvThongTinDocGia_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (dtgvThongTinDocGia.Rows == null)
            {
                txtThemMaDocGia.Text = "";
                return;
            }
            txtThemMaDocGia.Text = dtgvThongTinDocGia.Rows[e.RowIndex].Cells[0].Value.ToString();
        }

        

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtThemMaSach.Text == "" || txtThemMaDocGia.Text == "")
            {
                MessageBox.Show("Chua chon Sach hoac Doc Gia");
            }

            MuonTra MuonTra = new MuonTra(txtThemMaDocGia.Text, txtThemMaSach.Text, DateTime.Now, dtpkNgayGiaHan.Value);
            busMuonTra busMuonTra = new busMuonTra();
            busMuonTra.ThemMuonTra(MuonTra);

        }

    }
}
